import { ComponentArgs } from "../filesystem"
import { IComponent } from "./sys";
export class TextField extends IComponent {

    /**
     *文本编辑区域显示内容 
     */
    private textContent: string;

    /**
     * 额外挂载的参数
     */
    public extra?: object;

    /**
     * 传入的构造参数
     */
    public data: TextFieldArgs;

    constructor(args: TextFieldArgs) {
        super(args);
        this._init(args);
    }

    private _init(args: TextFieldArgs) {
        this.data = args;
        if (args.classList === null || args.classList === undefined) {
            this.classList = [];
        } else {
            this.classList = args.classList;
        }
        this.classList.push("textfile");
        this.textContent = args.textContent;
        this.extra = args.extra || null;
        let domBase = this._createDomBase(args);
        domBase.textContent = this.textContent;
        args.color || (domBase.style.color = args.color);
        args.backgroundColor || (domBase.style.backgroundColor = args.backgroundColor);
        args.rows ? (<HTMLTextAreaElement>domBase).rows = args.rows : (<HTMLTextAreaElement>domBase).rows = 80;
        args.columns || ((<HTMLTextAreaElement>domBase).cols = args.columns);
    }

    protected _createDomBase(args: TextFieldArgs): HTMLElement {
        return super._createDomBase(args, "textarea");
    }

    public setExtra(extra?: object) {
        this.extra = extra || null;
    }

    public setContent(textContent: string) {
        this.textContent = textContent;
        (<HTMLTextAreaElement>this.domBase).value = textContent;
    }
}
export interface TextFieldArgs extends ComponentArgs {

    /**
     * 背景色
     */
    backgroundColor?: string,

    /**
     *字体颜色
     */
    color?: string,

    /**
     * 列数
     */
    columns?: number;

    /**
     * 行数
     */
    rows?: number;

    /**
     *文本框内容 
     */
    textContent: string,

    /**
    *所有额外的参数
    */
    extra?: object;
}